package br.com.reparoja.reparoja;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

public class EncontrarAssistencia extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_encontrar_assistencia);

        ActionBar mActionBar = getSupportActionBar();
        mActionBar.setDisplayShowHomeEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(false);
        LayoutInflater mInflater = LayoutInflater.from(this);
        View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
        TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
        mTitleTextView.setText("ENCONTRAR ASSISTÊNCIA");
        mActionBar.setCustomView(mCustomView);
        mActionBar.setDisplayShowCustomEnabled(true);
        ImageButton imageButton = (ImageButton)mCustomView.findViewById(R.id.imageButton);
        imageButton.setImageResource(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        imageButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                finish();
            }
        });


        buscarEquipamentos();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_encontrar_assistencia, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        MenuItem item= menu.findItem(R.id.action_settings);
        item.setVisible(false);
        super.onPrepareOptionsMenu(menu);
        return false;
    }
    public void buscarEquipamentos()
    {/*
        AsyncHttp lalala = new AsyncHttp();
        lalala.url = "http://reparoja-br.appspot.com/Equipments";
        lalala.adpt = this;
        lalala.execute();
        */
    }
    public void preencherSpinner(ArrayList<HashMap<Integer, String>> items)
    {
        Spinner lisSpinner = (Spinner) findViewById(R.id.equipamentos);
        ArrayList<String> itemsToAdapter = new ArrayList<String>();
        for (int i = 0 ; i < items.size(); i++)
        {
            itemsToAdapter.add(items.get(i).values().toString());
        }
        ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, itemsToAdapter);

        adp.setDropDownViewResource(android.R.layout.simple_spinner_item);
        lisSpinner.setAdapter(adp);
    }


}
